<template>
  <div class="app-container">
    <el-form class="list-search" :model="queryParams" ref="queryRef" :inline="true" label-width="100">
      <el-form-item label="请选择公司" v-if="user.userType != 2" prop="companyCode">
        <el-select v-model="queryParams.companyCode" placeholder="请选择公司" clearable style="width: 240px">
          <el-option v-for="dict in companyList" :key="dict.companyCode" :label="dict.companyName"
            :value="dict.companyCode" />
        </el-select>
      </el-form-item>
      <el-form-item label="关键字" prop="userKeyWord">
        <el-input v-model="queryParams.userKeyWord" placeholder="请输入手机号、昵称"></el-input>
      </el-form-item>
      <el-form-item label="标题" prop="questionnaireTitle">
        <el-input v-model="queryParams.questionnaireTitle" placeholder="请输入标题"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="search()">
          搜索
        </el-button>
        <el-button icon="Refresh" @click="refresh">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="用户手机号" align="center" prop="contactNumber" />
      <el-table-column label="用户昵称" align="center" prop="nickName" />
      

      <el-table-column label="归属公司" v-if="user.userType != 2" align="center" prop="tel">
        <template #default="{ row }">
          {{
            filterName(
              companyList,
              row.companyCode,
              "companyCode",
              "companyName"
            )
          }}
        </template>
      </el-table-column>
      <el-table-column label="题案标题" align="center" prop="questionnaireTitle" />

      <el-table-column label="提交时间" align="center" prop="submissionTime" />
      <el-table-column label="操作" align="center">
        <template #default="{ row }">
          <el-button link type="primary" @click="getDetail(row)">
            查看详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
    <el-drawer title="提交详情" v-model="open" size="900px" append-to-body>
      <div class="title" style="text-align: center; font-weight: bold; font-size: 18px">
        {{ dataInfo.questionnaireTitle }}
      </div>
      <div class="list_item" v-for="(item, index) in dataInfo.questionList">
        <div>{{ index + 1 }}：{{ item.questionTitle }}</div>
        <div class="ans" v-if="item.questionType == 1">
          <el-radio-group :model-value="item.questionOptionList.find((itn) => itn.isCheck == 1)
              .optionContent
            " disabled class="ml-4">
            <el-radio :value="itg.optionContent" size="large" v-for="itg in item.questionOptionList">{{
              itg.optionContent
              }}</el-radio>
          </el-radio-group>
        </div>

        <div class="ans" v-if="item.questionType == 2">
          <el-checkbox :model-value="itg.isCheck != 0" :label="itg.optionContent" v-for="itg in item.questionOptionList"
            disabled size="large" />
        </div>
        <div class="ans" v-if="item.questionType == 3 || item.questionType == 4">
          <span style="color: #666"> {{ item.optionIsText }}</span>
        </div>
      </div>
    </el-drawer>
  </div>
</template>

<script setup name="WebsiteRecord">
import {
  querySubmissionRecord,
  queryBasicCompany,
  querySubmissionRecordDetails,
} from "@/api/website/index";
import useUserStore from "@/store/modules/user";
let user = useUserStore();

let loading = ref(false);
let dataList = ref([]);
let queryParams = ref({
  pageNum: 1,
  pageSize: 10,
});

let companyList = ref([]);
function getCompanyList() {
  queryBasicCompany({
    pageNum: 1,
    pageSize: 999,
  }).then((res) => {
    companyList.value = res.rows;
  });
}
getCompanyList();
// 获取详情
let dataInfo = ref();
function getDetail(row) {
  querySubmissionRecordDetails(row.id).then((res) => {
    dataInfo.value = res.data;
    open.value = true;
  });
}
// 获取页面列表
let total = ref(0);
function getList() {
  loading.value = true;
  querySubmissionRecord(queryParams.value)
    .then((res) => {
      dataList.value = res.rows;
      total.value = res.total;
      loading.value = false;
    })
    .catch((err) => {
      loading.value = false;
    });
}
getList();
let open = ref(false);
function search() {
  queryParams.value.pageNum = 1;
  getList();
}
function refresh() {
  queryParams.value.pageNum = 1;
  queryParams.value.companyCode = "";
  queryParams.value.userKeyWord = "";
  queryParams.value.questionnaireTitle = "";
  getList();
}
let list = ref([
  {
    title: "你吃饭了吗？你吃饭了吗？你吃饭了吗？你吃饭了吗？你吃饭了吗？",
    type: "1",
    ansList: ["没有", "有"],
    daan: "有",
  },
  {
    title: "你吃饭了吗？你吃饭了吗？你吃饭了吗？你吃饭了吗？你吃饭了吗？",
    type: "3",
    ansList: ["没有", "有"],
    daan: "有",
  },
  {
    title: "你吃饭了吗？你吃饭了吗？你吃饭了吗？你吃饭了吗？你吃饭了吗？",
    type: "2",
    ansList: ["没有", "有"],
    daan: ["没有", "有"],
  },
]);
</script>

<style scoped lang="scss">
.userImg {
  width: 50px;
  height: 50px;
}

.list_item {
  color: #333;

  .ans {
    padding: 10px 30px;
  }
}
</style>
